/***************************************************************************
 * 
 * Copyright (c) 2012 Baidu.com, Inc. All Rights Reserved
 * 
 **************************************************************************/
 
 
 
/**
 * @file main.cpp
 * @author dujialun01(com@baidu.com)
 * @date 2012/06/11 20:43:32
 * @brief 
 *  
 **/

#include <algorithm>
#include <cmath>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
using namespace std;

const double    g_e = 1e-5;

typedef struct _ellipse_t
{
    int     id;
    double  x;
    double  y;
    double  a00;
    double  a01;
    double  a10;
    double  a11;

public:
    bool point_in_ellipse(double x, double y)
    {
        double  denominator = a00 * a11 - a01 * a10;
        if (fabs(denominator) < g_e)
        {
            return false;
        }
        double  x1 = a11 / denominator;
        double  x2 = -a01 / denominator;
        double  x3 = -a10 / denominator;
        double  x4 = a00 / denominator;
        double  t1 = x1 * (x - this->x) + x2 * (y - this->y);
        double  t2 = x3 * (x - this->x) + x4 * (y - this->y);
        if (t1 * t1 + t2 * t2 <= 1)
        {
            return true;
        }
        return false;
    }
}ellipse_t;

vector<double>  g_vec_xlist;
vector<double>  g_vec_ylist;
vector<ellipse_t>   g_vec_ellipse;
map<int, map<int, vector<ellipse_t> > >   g_map_index;

int read_file(char *file)
{
    FILE    *fp = fopen(file, "r");
    if (fp == NULL)
    {
        fprintf(stderr, "open %s fail\n", file);
        return -1;
    }
    char    line[10240];
    while (!feof(fp))
    {
        if (fgets(line, 10240, fp) == NULL)
        {
            continue;
        }
        ellipse_t   ellipse;
        int ret = sscanf(line, "%d\t%lf%lf%lf%lf%lf%lf", 
                &(ellipse.id),
                &(ellipse.x),
                &(ellipse.y),
                &(ellipse.a00),
                &(ellipse.a01),
                &(ellipse.a10),
                &(ellipse.a11)
                );
        if (ret != 7)
        {
            fprintf(stderr, "invalid line:%s", line);
            return -1;
        }
        g_vec_ellipse.push_back(ellipse);
    }
    fclose(fp);
    return 0;
}

int init()
{
    for (int i = 0; i < g_vec_ellipse.size(); ++i)
    {
        ellipse_t   ellipse = g_vec_ellipse[i];
        double  x1 = ellipse.x + ellipse.a00;
        double  x2 = ellipse.x - ellipse.a00;
        double  y1 = ellipse.y + ellipse.a11;
        double  y2 = ellipse.y - ellipse.a11;
        g_vec_xlist.push_back(x1);
        g_vec_xlist.push_back(x2);
        g_vec_ylist.push_back(y1);
        g_vec_ylist.push_back(y2);
    }
    sort(g_vec_xlist.begin(), g_vec_xlist.end());
    sort(g_vec_ylist.begin(), g_vec_ylist.end());
    for (int i = 0; i < g_vec_ellipse.size(); ++i)
    {
        ellipse_t   ellipse = g_vec_ellipse[i];
        double  x_min = ellipse.x - ellipse.a00;
        double  x_max = ellipse.x + ellipse.a00;
        double  y_min = ellipse.y - ellipse.a11;
        double  y_max = ellipse.y + ellipse.a11;
        if (x_min > x_max)
        {
            swap(x_min, x_max);
        }
        if (y_min > y_max)
        {
            swap(y_min, y_max);
        }
        int x_idx_1, x_idx_2, y_idx_1, y_idx_2;
        vector<double>::iterator ite;
        ite = lower_bound(g_vec_xlist.begin(), g_vec_xlist.end(), x_min);
        x_idx_1 = ite - g_vec_xlist.begin();
        ite = lower_bound(g_vec_xlist.begin(), g_vec_xlist.end(), x_max);
        x_idx_2 = ite - g_vec_xlist.begin();
        ite = lower_bound(g_vec_ylist.begin(), g_vec_ylist.end(), y_min);
        y_idx_1 = ite - g_vec_ylist.begin();
        ite = lower_bound(g_vec_ylist.begin(), g_vec_ylist.end(), y_max);
        y_idx_2 = ite - g_vec_ylist.begin();
        for (int j = x_idx_1 + 1; j <= x_idx_2; ++j)
        {
            for (int k = y_idx_1 + 1; k <= y_idx_2; ++k)
            {
                g_map_index[j][k].push_back(ellipse);
            }
        }
    }
}

int search(double x, double y)
{
    vector<double>::iterator    ite;
    int x_idx, y_idx;
    ite = lower_bound(g_vec_xlist.begin(), g_vec_xlist.end(), x);
    if (ite == g_vec_xlist.end())
    {
        return 0;
    }
    x_idx = ite - g_vec_xlist.begin();
    ite = lower_bound(g_vec_ylist.begin(), g_vec_ylist.end(), y);
    if (ite == g_vec_ylist.end())
    {
        return 0;
    }
    y_idx = ite - g_vec_ylist.begin();
    vector<ellipse_t>::iterator ite1;
    for (ite1 = g_map_index[x_idx][y_idx].begin(); ite1 != g_map_index[x_idx][y_idx].end(); ++ite1)
    {
        if (ite1->point_in_ellipse(x, y))
        {
            return ite1->id;
        }
    }
    return 0;
}

int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        fprintf(stderr, "argument error\n");
        exit(1);
    }
    if (read_file(argv[1]) < 0)
    {
        fprintf(stderr, "read_file fail\n");
        exit(1);
    }
    init();
    char    line[10240];
    while (cin.getline(line, 10240))
    {
        double  x, y;
        int ret;
        ret = sscanf(line, "%lf%lf", &x, &y);
        if (ret != 2)
        {
            printf("0\n");
            continue;
        }
        int aoi_id = search(x, y);
        printf("%d\n", aoi_id);
    }
    return 0;
}



/* vim: set expandtab ts=4 sw=4 sts=4 tw=100: */
